<?php

use App\Http\Controllers\AggregateFixReportController;
use App\Http\Controllers\AggregateReportController;
use App\Http\Controllers\DictController;
use App\Http\Controllers\DistrictController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\SheetTemplateController;
use App\Http\Controllers\SubTaskController;
use App\Http\Controllers\TaskController;
use App\Http\Controllers\TaskTemplateController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\UtilsController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
 */
if (env('APP_DEBUG')) {
    Route::any('user/test', [UserController::class, 'test']);
}

Route::prefix('user')->middleware(['api'])->group(function () {
    Route::post('/send-sms-code', [UserController::class, 'sendSmsCode']);
    Route::post('/login-by-code', [UserController::class, 'loginByCode']);
    Route::post('/login', [UserController::class, 'login']);
    Route::post('/assign-role', [UserController::class, 'assignRole']);
});

Route::middleware(['api', 'auth:sanctum'])->group(function () {
    Route::prefix('user')->group(function () {
        Route::get('/info', [UserController::class, 'info']);
        Route::post('/logout', [UserController::class, 'logout']);
        Route::post('/update', [UserController::class, 'update']);
        Route::get('/role-list', [UserController::class, 'roleList']);

        Route::post('/create', [UserController::class, 'create']);
        Route::get('/list', [UserController::class, 'list']);
        Route::get('/show', [UserController::class, 'show']);
        Route::post('/delete', [UserController::class, 'delete']);
        Route::post('/modify-password', [UserController::class, 'modifyPassword']);
    });

    Route::prefix('sheet-template')->group(function () {
        Route::get('/list', [SheetTemplateController::class, 'list']);
        Route::get('/show', [SheetTemplateController::class, 'show']);
    });

    Route::prefix('task-template')->group(function () {
        Route::post('/create', [TaskTemplateController::class, 'create']);
        Route::get('/list', [TaskTemplateController::class, 'list']);
        Route::get('/show', [TaskTemplateController::class, 'show']);
        Route::post('/update', [TaskTemplateController::class, 'update']);
        Route::post('/delete', [TaskTemplateController::class, 'delete']);
        Route::post('/manual-publish', [TaskTemplateController::class, 'manualPublish']);
    });

    Route::prefix('task')->group(function () {
        Route::get('/list', [TaskController::class, 'list']);
        Route::get('/show', [TaskController::class, 'show']);
        Route::post('/update', [TaskController::class, 'update']);
        Route::post('/publish', [TaskController::class, 'publish']);
        Route::post('/remind', [TaskController::class, 'remind']);
        Route::post('/revoke', [TaskController::class, 'revoke']);
        Route::get('/stat', [TaskController::class, 'stat']);
        Route::post('/fire-aggregate', [TaskController::class, 'fireAggregate']);
    });

    Route::prefix('sub-task')->group(function () {
        Route::get('/list', [SubTaskController::class, 'list']);
        Route::get('/show', [SubTaskController::class, 'show']);
        Route::post('/report', [SubTaskController::class, 'report']);
        Route::post('/review1', [SubTaskController::class, 'review1']);
        Route::post('/review2', [SubTaskController::class, 'review2']);
        Route::post('/reset', [SubTaskController::class, 'reset']);
        Route::get('/export', [SubTaskController::class, 'export']);
        Route::post('/update-force', [SubTaskController::class, 'updateForce']);
    });

    Route::prefix('aggregate-report')->group(function () {
        Route::get('/list', [AggregateReportController::class, 'list']);
        Route::get('/show', [AggregateReportController::class, 'show']);
        Route::get('/export', [AggregateReportController::class, 'export']);
        Route::post('/fix', [AggregateReportController::class, 'fix']);
    });

    Route::prefix('aggregate-fix-report')->group(function () {
        Route::get('/list', [AggregateFixReportController::class, 'list']);
        Route::get('/show', [AggregateFixReportController::class, 'show']);
        Route::post('/update', [AggregateFixReportController::class, 'update']);
        Route::get('/export', [AggregateFixReportController::class, 'export']);
    });

    Route::prefix('dict')->group(function () {
        Route::get('/list', [DictController::class, 'list']);
        Route::get('/category-list', [DictController::class, 'categoryList']);
        Route::get('/show', [DictController::class, 'show']);
        Route::post('/create', [DictController::class, 'create']);
        Route::post('/update', [DictController::class, 'update']);
        Route::post('/delete', [DictController::class, 'delete']);
    });

    Route::prefix('utils')->group(function () {
        Route::post('/upload', [UtilsController::class, 'upload']);
    });

    Route::prefix('district')->group(function () {
        Route::get('/list', [DistrictController::class, 'list']);
        Route::post('/create', [DistrictController::class, 'create']);
        Route::post('/update', [DistrictController::class, 'update']);
        Route::post('/delete', [DistrictController::class, 'delete']);
    });

    Route::prefix('home')->group(function () {
        Route::get('/', [HomeController::class, 'index']);
    });
});

Route::middleware(['api'])->group(function () {
    Route::get('captcha/{config?}', [\Mews\Captcha\CaptchaController::class, 'getCaptchaApi']);
});
